package com.sky.task;

import com.sky.entity.Orders;
import com.sky.mapper.OrderMapper;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;

import java.time.LocalDateTime;
import java.util.List;

/**
 * 订单任务
 *
 * @author liudo
 * @version 1.0
 * @project sky-take-out
 * @date 2023/12/15 09:38:23
 */
@Slf4j
@Component
public class OrderTask {

    @Autowired
    private OrderMapper orderMapper;

    /**
     * 每分钟去查一次 超时订单  更改状态
     */
    @Scheduled(cron = "0 0/1 * * * ?")
    public void automaticCancellationOrders() {
        log.info("----------自动取消订单：开始--------------");
        orderMapper.updateStatusBeforeTime();
        log.info("----------自动取消订单：结束--------------");
    }

    /**
     * 凌晨： 用户量低峰期：系统压力小
     * 业务的性质： 当日一次性完成
     */
    @Scheduled(cron = "0 0 2 * * ? ")
    public void automaticallyCompleteOrders() {
        log.info("----------自动完成订单：开始--------------");
        Integer integer = orderMapper.updateStatusByStatus();
        log.info("----------自动完成订单{}单：结束--------------", integer);
    }
}
